﻿Imports MICROFORMA.BLL

Public Class frmDataExternal

    Dim datoExternoBL As DatosExternosBL

    Dim dtableQuery As DataTable

    Private Sub btnTestQuery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTestQuery.Click
        If ValidaForm() Then
            If ValidaTestQuery() Then
                Call MessageMistake("Prueba Realizada con exito.!!!", True)
            Else
                Call MessageMistake("Ingrese una Consulta Válida.")
            End If
        End If
    End Sub

    Private Sub frmDataExternal_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Call LoadComboNamesConnections()
    End Sub

    Private Sub LoadComboNamesConnections()
        datoExternoBL = New DatosExternosBL
        cboNameConexion.DataSource = datoExternoBL.getList
        cboNameConexion.ValueMember = "IdDatoExterno"
        cboNameConexion.DisplayMember = "CadenaConexion"
    End Sub

    Public Function ValidaTestQuery() As Boolean
        Dim ListasBL As ListasBL
        ListasBL = New ListasBL
        If Not ListasBL.TestQuery(cboNameConexion.Text, txtQuerySql.Text) Is Nothing Then
            ValidaTestQuery = True
        Else
            ValidaTestQuery = False
        End If
    End Function

    Function ValidaForm() As Boolean

        If cboNameConexion.SelectedIndex <> 0 Then
            MessageMistake("Por favor seleccione un tipo de conexion del listado.")
            cboNameConexion.Focus()
            Exit Function
        End If

        If Trim(txtQuerySql.Text) = "" Then
            MessageMistake("Por favor ingrese la sentencia para efectuar la consulta respectiva.")
            txtQuerySql.Focus()
            Exit Function
        End If

        ValidaForm = True

    End Function

    Private Sub btnAccept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAccept.Click
        If ValidaTestQuery() Then
            Me.Close()
        Else
            MessageMistake("Por favor Ingrese una Consulta Válida.")
            txtQuerySql.Focus()
        End If
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        txtQuerySql.Text = ""
        Me.Close()
    End Sub

End Class